package com.roc.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import com.roc.util.Constance;



public class AmountTags extends TagSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1530895548713323241L;
	
	private Double amount;

	@Override
	public int doEndTag() throws JspException {
		
		
		return super.EVAL_PAGE;
		
		//return super.SKIP_PAGE;
	}

	@Override
	public int doStartTag() throws JspException {
		
		PageContext  pc=super.pageContext;
		
		JspWriter out=pc.getOut();
		try{
			String amountStr="";
			if(amount==0){
				amountStr="0.00";
			}else{
				amountStr=Constance.numberFormat(amount);
				if(amountStr.contains(".")){
					if(amountStr.substring(amountStr.lastIndexOf(".")+1).length()==1){
						amountStr=amountStr+"0";
					}
					if(amountStr.substring(amountStr.lastIndexOf(".")+1).length()==2){
						amountStr=amountStr;
					}
				}else{
					amountStr=amountStr+".00";
				}
			}
			
			out.println(amountStr);
		}catch(IOException e){
			e.printStackTrace();
		}
		
		
		return super.SKIP_BODY;
		
	}

	public void setAmount(double amount){
		this.amount=amount;
	}
	
}
